﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ItemInfo : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    [SerializeField]
    private Item item;
    [SerializeField]
    private Image image;
    [SerializeField]
    private Text title;
    [SerializeField]
    private Text counter;
    private int maxCount=1;

    public Item MyItem { get => item; set => item=value; }
    
    public void Initialize(Item item, int count)
    {
        this.MyItem = item;
        this.image.sprite = item.MyIcon;
        this.maxCount = count;
        this.title.text = string.Format("<color={0}>{1}</color>", ItemRarityColor.MyRarityColours[item.MyItemRarity], item.MyTitle);
        if (count > 1)
        {

            counter.enabled = true;
            this.counter.text = inventoryScript.MyInstance.GetItemCount(item.MyTitle).ToString()+"/" + count.ToString();
            
        }
    }
       
    public void UpdateStackCount()
    {
        counter.text= inventoryScript.MyInstance.GetItemCount(item.MyTitle).ToString() + "/" + maxCount.ToString();
    }
    public void OnPointerEnter(PointerEventData eventData)
    {
        UIManager.MyInstance.showToolTip(new Vector2(), transform.position, MyItem);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        UIManager.MyInstance.hideToolTip();
    }

}
